/**
* ...
* @author Default
* @version 0.1
*/

import mx.events.EventDispatcher

class classes.data.XMLParser extends EventDispatcher
{
	private var m_objXML:XML;
	private var m_intCurrentSegment:Number;

	public function XMLParser()
	{
		var objThis = this;
		m_objXML = new XML();
		m_objXML.ignoreWhite = true;
		m_objXML.onLoad = function(s)
		{
			objThis.parseXML(this);
		}
		m_objXML.load("xml/UpFront.xml");
	}


	private function parseXML(_xml:XML):Void
	{
		var objEvent:Object = new Object();
		objEvent.type = "complete";
		objEvent.target = this;
		objEvent.data = _xml;

		dispatchEvent(objEvent)
	}

	public function getSegmentNameFor(_intSegmentIndex):String
	{
		return m_objXML.firstChild.childNodes[1].childNodes[_intSegmentIndex].attributes.name;
	}


	public function get currentSegmentName():String
	{
		return m_objXML.firstChild.childNodes[1].childNodes[currentSegmentIndex].attributes.name;
	}

	public function get currentSegmentPath():String
	{
		return m_objXML.firstChild.childNodes[1].childNodes[currentSegmentIndex].attributes.swfPath;
	}


	public function get defaultProgressLabel():String
	{
		return m_objXML.firstChild.childNodes[0].childNodes[1].attributes.label;
	}

	public function get length():Number
	{
		return m_objXML.firstChild.childNodes[1].childNodes.length;
	}

	public function get controlsRequired():Boolean
	{
		return m_objXML.firstChild.childNodes[1].childNodes[currentSegmentIndex].attributes.video_controls_required == "yes" ? true : false;
	}

	public function set currentSegmentIndex(_index:Number):Void
	{
		m_intCurrentSegment = _index;
	}

	public function get currentSegmentIndex():Number
	{
		return m_intCurrentSegment;
	}

	public function get videoList():Array
	{
		var arrFileList:Array = new Array();
		for(var i=0; i<m_objXML.firstChild.childNodes[2].childNodes.length; i++)
		{
			arrFileList.push(m_objXML.firstChild.childNodes[2].childNodes[i].attributes.file_path);
		}
		return arrFileList;
	}

	public function get swfList():Array
	{
		var arrFileList:Array = new Array();
		for(var i=0; i<m_objXML.firstChild.childNodes[3].childNodes.length; i++)
		{
			arrFileList.push(m_objXML.firstChild.childNodes[3].childNodes[i].attributes.file_path);
		}
		return arrFileList;
	}

}